import sys  
import time  
import cv2  
  
if len(sys.argv) < 2:  
    print("请输入图像路径...")  
    exit()  
  
# No Transparent API  
mat_start = time.time()  
img = cv2.imread(sys.argv[1], cv2.IMREAD_COLOR)  
  
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  
gray = cv2.GaussianBlur(gray, (7, 7), 1.5)  
gray = cv2.Canny(gray, 0, 50)  
  
print('Mat costs time: %f s...' % (time.time() - mat_start))  
cv2.imshow("edges", gray)  
  
# Transparent API  
umat_start = time.time()  
img_temp = cv2.UMat(cv2.imread(sys.argv[1], cv2.IMREAD_COLOR))  
  
imgUMat = cv2.UMat(img_temp)  
ugray = cv2.cvtColor(imgUMat, cv2.COLOR_BGR2GRAY)  
ugray = cv2.GaussianBlur(gray, (7,7), 1.5)  
ugray = cv2.Canny(ugray, 0, 50)  
  
print('UMat costs time: %f s...' % (time.time() - umat_start))  
cv2.imshow("edges_UMat", ugray)  
cv2.waitKey(0)  